﻿@Styles.Render("~/Content/Upload/uploadify.css")
@Scripts.Render("~/Scripts/swfobject.js")
@Scripts.Render("~/Scripts/jquery.uploadify.v2.1.4.js")


    <input type="file" id="filename" name="filename" />
    <p>
        <button id="upload-file" class="btn">Subir Foto</button>
    </p>
    <div id="message"></div>

@*<fieldset>
    <legend></legend>
    <ul id="photoList">
    </ul>
</fieldset>*@


<script type="text/javascript">
    $(function () {
        // Get a reference to the div for messages.
        var message = $("#message");

        // Initialize the plugin to the "file" input element.
        $("#filename").uploadify({
            'uploader': '@Url.Content("~/Scripts/uploadify.swf")',
            'script': '@Url.Action("Upload", "Usuarios")',
            'multi': true,
            'cancelImg': '@Url.Content("~/Content/images/cancel.png")',
            'folder': '/FicherosSubidos/',
            'fileDataName': 'fileData',
            'fileDesc': 'Upload an image file',
            'fileExt': '*.*',
            'onError': function (event, queue, fileInfo, error) {
                // Display the error message in red.
                message.css("color", "red");
                message.html("Error " + error.type + ": " + error.text);
            },
            'onComplete': function (event, queueId, fileObj, response, data) {
                // Display the successful message in green and fade out 
                // after 3 seconds. 
                message.css("color", "green");
                message.html("Foto enviada con exito.");
                message.fadeIn().delay(3000).fadeOut();

                //Insert path de la foto 
                document.getElementById("usuario_foto").value = response;
                //Poner la imagen
                document.getElementById("id_img_foto").src = response;

            }
        });

        // The event handler for the Upload button.
        $("#upload-file").click(function () {
            // Refer to the documentation for this method...
            // $("#some-file-input").uploadifyUpload();
            // http://www.uploadify.com/documentation/
            $("#filename").uploadifyUpload();
        });

    });
</script>
